#!/usr/bin/env python3
# -*- coding: utf-8 -*-
##############################################
# @Author: DengLibin 榆霖
# @Date: Create in 2022-03-14 15:53:24
# @Description: 
##############################################

import numpy as np
from numpy import random

##############################################
# @Author: DengLibin 榆霖
# @Date: Create in 2022-03-14 16:00:19
# @Description: ndarray 数组
##############################################
def run():
    
     # 4*4 随机数组
    arr = random.rand(4, 4)
    # numpy.ndarray (4, 4)
    print(arr, type(arr), arr.shape)
    print("------------------------------------------------------------")
    arr = np.array([[1, 2, 3], [4, 6, 6]], dtype=np.int32)
    print(arr.shape) # (2, 3) 两行三列
    print(arr.ndim) # 2 维
    print(arr.size) # 元素个数 6
    print(arr.itemsize) # 每个元素的大小 4
    print(arr.dtype)# 数据类型 int32
    

##############################################
# @Author: DengLibin 榆霖
# @Date: Create in 2022-03-14 16:05:51
# @Description: 生成数组
##############################################
def create_arr():
    #  生成0，1数组
    ar = np.ones([4, 8], dtype=np.int32) # 4行8列
    print(ar)
    # 4, 8
    print(ar.shape[0], ar.shape[1])
    x = 0
    for i in range(0, 4):
        for j in range(0, 8):
            ar[i, j] = x
            x += 1

    print(ar)
    
    # 第一列 1维
    print("ar[:, 0]::::::::::::::::", ar[:, 0], ar[:, 0].shape)
    print("--------------------------------------------------------------------------")
     # 第一列 4行1列 2维
    print("ar[:, 0:1]::::::::::::::::", ar[:, :1], ar[:, 0:1].shape)
    print("--------------------------------------------------------------------------")
    # 第一行 1维
    print("ar[0, :]::::::::::::::::", ar[0, :], ar[0, :].shape)
    print("--------------------------------------------------------------------------")
    # 第一行 1行8列
    print("ar[0:1, :]::::::::::::::::", ar[0:1, :], ar[0:1, :].shape)
    print("--------------------------------------------------------------------------")
    
    ar = np.zeros([4, 8], dtype=np.int32)
    print(ar)
    
    
    # 修改元素值
    ar[(0, 1)] = 4
    print(ar)
    
    # 生成固定范围的数组
    print(np.linspace(0, 16, 9, dtype=np.int32)) # 等差数组
    print(np.arange(10, 100, 2, dtype=np.int32)) #等差数组，包含头不包含尾，步长=2
    print(np.logspace(0, 3, 8, dtype=np.int32)) # 10^0 到10^3生成8个数
    

if __name__ == '__main__':
#    run()
     create_arr()
